package org.upfrost.util;

import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

public class ArrayUtils
{
	
	final static public <T> List<T> asList(T...ts)
	{
		List<T> list = new LinkedList<T>();
		for (T t: ts)
			list.add(t);
		return list;
	}
	
	final public static <T> List<T> asArrayList(T...ts)
	{
		ArrayList<T> list = new ArrayList<T>(ts.length);
		for (T t: ts)
			list.add(t);
		return list;
	}
	
	final public static <T> boolean contains(T element, T... ts)
	{
		for (T t: ts)
		{
			if (element.equals(t))
				return true;
		}
		return false;
	}
	
	final public static <T> T[] join(T[] arr, T el)
	{
		T[] n = (T[]) Array.newInstance(arr.getClass().getComponentType(), arr.length+1);
		for (int i=0; i<arr.length; i++)
			n[i] = arr[i];
		n[arr.length] = el;
		return n;
	}

	final public static <T> T pickRandomElement(T[] arr)
	{
		double length = (double)arr.length;
		return arr[ (int)Math.floor(Math.random() * length) ];
	}
	
}
